package com.mall.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.entity.Coupon;
import com.mall.mapper.CouponMapper;
import com.mall.service.ICouponService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 优惠券表 服务实现类
 * </p>
 *
 * @author sppxpp
 * @since 2023-04-16
 */
@Service
public class CouponServiceImpl implements ICouponService {
    final
    CouponMapper couponMapper;

    public CouponServiceImpl(CouponMapper couponMapper) {
        this.couponMapper = couponMapper;
    }

    /**
     * 查询优惠券
     *
     * @param page 页
     * @return list
     */
    @Override
    public IPage<Coupon> queryCoupon(Page<Coupon> page) {
        return couponMapper.selectPage(page,null);
    }

    /**
     * 查询优惠券
     *
     * @return list
     */
    @Override
    public List<Coupon> queryCoupon() {
        return couponMapper.selectList(null);
    }

    /**
     * 查询优惠券
     *
     * @param id id
     * @return list
     */
    @Override
    public Coupon queryCouponById(Integer id) {
        return couponMapper.selectById(id);
    }

    /**
     * 删除优惠券
     *
     * @param ids ids
     * @return success count
     */
    @Override
    public Integer deleteCoupon(List<String> ids) {
        return couponMapper.deleteBatchIds(ids);
    }

    /**
     * 修改优惠券
     *
     * @param coupon entity
     * @return bool
     */
    @Override
    public Boolean updateCoupon(Coupon coupon) {
        return couponMapper.updateById(coupon) > 0;
    }

    /**
     * 添加优惠券
     *
     * @param coupon entity
     * @return bool
     */
    @Override
    public Boolean addCoupon(Coupon coupon) {
        return couponMapper.insert(coupon) > 0;
    }
}
